package script;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.testng.annotations.Test;

public class TestJsoup {
    @Test
    public void test01(){
        String form = "<html>\n" +
                "<head><title>黑马程序员</title></head>\n" +
                "<body>\n" +
                "    <p id=\"test01\">软件测试</p>\n" +
                "    <p id=\"test02\">2020年</p>\n" +
                "    <a href=\"/api.html\">接口测试</a>\n" +
                "    <a href=\"/web.html\">Web自动化测试</a>\n" +
                "    <a href=\"/app.html\">APP自动化测试</a>\n" +
                "</body>\n" +
                "</html>";
        //解析html数据
        Document document = Jsoup.parse(form);
        //获取第一个p标签
        Element p1 = document.getElementsByTag("p").first();
        System.out.println("p1="+p1.text());
        //获取id等于test02标签
        Element test02 = document.getElementById("test02");
        System.out.println(test02.text());
        //获取所有a标签
        Elements a = document.getElementsByTag("a");
        for (Element e:a){
            System.out.println(e.attr("href")+"=="+e.text());
        }

    }




}

